<template>
  <div class="app-container">
    <eHeader :param-bean="paramBean" :sup_this="sup_this" />
    <eForm ref="form" :sup_this="sup_this" />
    <eFormDetail ref="formDetail" :sup_this="sup_this" />
    <historyList ref="historyList" :sup_this="sup_this" />
    <!--表格渲染-->
    <DataGridTable
      v-loading="loading"
      ref="mainTable"
      :sup_this="sup_this"
      :data="data.rtnList"
      :max-height="gridMaxHeight"
      :total="total"
      :show-cell-class="true"
      :show-row-complex-number="true"
      :all-define-columns="['sysOrgName','name','selfStateName','contractNo','contractType','amount','costAmount','beginDate','endDate','customSigner','companySigner','productAmount','productDisaccount','chargerName','lastUpdateDate',]"
      grid-id="contractMngProcessGridId"
      @toViewHistory="toViewHistory"
      @selection-change="handleGridSelectionChange">
      <DataGridColumnSlot prop="sysGenCode" label="业务类型">
        <template slot-scope="scope">
          <edit :data="scope.row" :sup_this="sup_this" />
        </template>
      </DataGridColumnSlot>
      <DataGridColumnSlot prop="busOtherCpyName" label="客户">
        <template slot-scope="scope">
          <a title="客户回访" @click="toVisit(scope.row)">{{ scope.row.busOtherCpyName }}</a>
        </template>
      </DataGridColumnSlot>
      <DataGridColumnSlot prop="busDate" label="业务时间">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.busDate) }}</span>
        </template>
      </DataGridColumnSlot>
      <DataGridColumn slot="sysOrgName" prop="sysOrgName" label="机构" />
      <DataGridColumn slot="name" prop="name" label="名称" />
      <DataGridColumn slot="selfStateName" prop="selfStateName" label="状态"/>
      <DataGridColumn slot="contractNo" prop="contractNo" label="合同编号" />
      <DataGridColumnSlot slot="contractType" prop="contractType" label="合同类型">
        <template slot-scope="scope">
          <template v-for="item in dicts.contract_type">
            <span v-if="scope.row.contractType.toString() === item.dictCode" :key="item.id" >{{ item.dictName }}</span>
          </template>
        </template>
      </DataGridColumnSlot>
      <DataGridColumn slot="amount" prop="amount" label="合同金额" />
      <DataGridColumn slot="costAmount" prop="costAmount" label="提成总金额" />
      <DataGridColumnSlot slot="beginDate" prop="beginDate" label="合同开始时间" >
        <template slot-scope="scope">
          <span>{{ parseDate(scope.row.beginDate) }}</span>
        </template>
      </DataGridColumnSlot>
      <DataGridColumnSlot slot="endDate" prop="endDate" label="合同结束时间" >
        <template slot-scope="scope">
          <span>{{ parseDate(scope.row.endDate) }}</span>
        </template>
      </DataGridColumnSlot>
      <DataGridColumn slot="customSigner" prop="customSigner" label="客户签约人" />
      <DataGridColumn slot="companySigner" prop="companySigner" label="公司签约人" />
      <DataGridColumn slot="productAmount" prop="productAmount" label="产品金额" />
      <DataGridColumn slot="productDisaccount" prop="productDisaccount" label="产品总折扣" />
      <DataGridColumn slot="chargerName" prop="chargerName" label="负责人" />
      <DataGridColumnSlot slot="lastUpdateDate" prop="lastUpdateDate" label="最后更新时间" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastUpdateDate) }}</span>
        </template>
      </DataGridColumnSlot>
    </DataGridTable>
  </div>
</template>

<script>
import { parseTime, parseDate } from '@/utils/index'
import eHeader from './module/header'
import edit from './module/edit'
import eForm from './module/form'
import historyList from './module/historyList'
import initData from '@/mixins/initData'
import contract from '@/api/crm/Contract'
import eFormDetail from './module/formDetail'

export default {
  components: { eHeader, eForm, eFormDetail, edit, historyList },
  dictTypes: ['contract_type'],
  mixins: [initData],
  props: {
  },
  data() {
    return {
      delLoading: false,
      sup_this: this
    }
  },
  created() {
    this.defaultParamBean.searchScene = 'me'
    this.url = contract.loadDataUrl()
    this.$nextTick(() => {
      this.resetQuery(true)
    })
  },
  mounted() {
  },
  methods: {
    parseTime,
    parseDate,
    toViewHistory(row) {
      this.openViewHistory(row, 'historyList')
    },
    async beforeInit() {
      return true
    },
    toVisit(rowData) {
      const _this = this.$refs.formDetail
      _this.initDataOfBefore()
      _this.viewMainData(rowData.id)
    }
  }
}
</script>
